package com.erp.auto.controller;

import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.erp.auto.domain.vo.ErpAutoPlanShareVo;
import com.erp.auto.domain.bo.ErpAutoPlanShareBo;
import com.erp.auto.service.IErpAutoPlanShareService;

/**
 * 自动化计划分享
 *
 * @author WXX
 * @date 2024-03-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/auto/autoPlanShare")
public class ErpAutoPlanShareController extends BaseController {

    private final IErpAutoPlanShareService iErpAutoPlanShareService;

    /**
     * 使用分享码
     */
    @GetMapping("/useShareCode")
    public R<Object> useShareCode(Long id) {
        return iErpAutoPlanShareService.useShareCode(id);
    }

    /**
     * 查询自动化计划分享列表
     */
//    @SaCheckPermission("auto:autoPlanShare:list")
    @GetMapping("/list")
    public TableDataInfo<ErpAutoPlanShareVo> list(ErpAutoPlanShareBo bo, PageQuery pageQuery) {
        return iErpAutoPlanShareService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出自动化计划分享列表
     */
//    @SaCheckPermission("auto:autoPlanShare:export")
    @Log(title = "自动化计划分享", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpAutoPlanShareBo bo, HttpServletResponse response) {
        List<ErpAutoPlanShareVo> list = iErpAutoPlanShareService.queryList(bo);
//        ExcelUtil.exportExcel(list, "自动化计划分享", ErpAutoPlanShareVo.class, response);
    }

    /**
     * 获取自动化计划分享详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("auto:autoPlanShare:query")
    @GetMapping("/{id}")
    public R<ErpAutoPlanShareVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpAutoPlanShareService.queryById(id));
    }

    /**
     * 新增自动化计划分享
     */
//    @SaCheckPermission("auto:autoPlanShare:add")
    @Log(title = "自动化计划分享", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Object> add(@Validated(AddGroup.class) @RequestBody ErpAutoPlanShareBo bo) {
        return iErpAutoPlanShareService.insertByBo(bo);
    }

    /**
     * 修改自动化计划分享
     */
//    @SaCheckPermission("auto:autoPlanShare:edit")
    @Log(title = "自动化计划分享", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpAutoPlanShareBo bo) {
        return toAjax(iErpAutoPlanShareService.updateByBo(bo));
    }

    /**
     * 删除自动化计划分享
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("auto:autoPlanShare:remove")
    @Log(title = "自动化计划分享", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpAutoPlanShareService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
